package com.wwj.depository.utils;

import java.util.ArrayList;
import java.util.List;

public class StorageCalculateUtil {

    /**
     * 计算仓位名
     */
    public static List<String> storageCalculation(String endLocationName,int stockEveryCollect,int requireNumber,int maxLimit) {
        int locationIndex0 = Integer.parseInt(endLocationName.split("-")[0]);
        int locationIndex1 = Integer.parseInt(endLocationName.split("-")[1]);
        List<String> list = new ArrayList<>();
        int number = 0;  // 计数
        for (int i = locationIndex1 + 1; i <= stockEveryCollect; i++) {
            // 处理当前位号剩余库存
            list.add(locationIndex0 + "-" + i);
            number++;
            if (number == requireNumber) {
                break;
            }
        }
        for (int i = locationIndex0 + 1; i <= maxLimit; i++) {
            for (int j = 1; j <= stockEveryCollect; j++) {
                if (number >= requireNumber) {
                    break;
                }
                list.add(i + "-" + j);
                number++;
            }
            if (number >= requireNumber) {
                break;
            }
        }
        return list;
    }

    /**
     * 计算开始、结束仓位范围
     */
    public static List<String> storageRange(String locationStart,String locationEnd,int stockEveryCollect,int maxLimit){
        List<String> list = new ArrayList<>();
        int locationStartIndex0 = Integer.parseInt(locationStart.split("-")[0]);
        int locationStartIndex1 = Integer.parseInt(locationStart.split("-")[1]);
        int locationEndIndex0 = Integer.parseInt(locationEnd.split("-")[0]);
        int locationEndIndex1 = Integer.parseInt(locationEnd.split("-")[1]);
        // 处理剩余
        for (int i = locationStartIndex1; i <= stockEveryCollect; i++) {
            list.add(locationStartIndex0 + "-" + i);
        }
        boolean flag = false;  // 标志位
        for (int i = locationStartIndex0 + 1; i <= maxLimit; i++ ){
            for (int j = 1; j <= stockEveryCollect; j++) {
                if (locationEnd.equals(i + "-" + j)) {
                    flag = true;
                    break;
                }
                list.add(i + "-" + j);
            }
            if (flag) {
                break;
            }
        }
        // 末尾处理
        list.add(locationEnd);
        return list;
    }
}

